Process Synchronization


Q32.

The following program consists of 3 concurrent processes and 3 binary semaphores. The semaphores are initialized as S0=1, S1=0, S2=0. How many times will process P0 print '0'? How many times will process P0 print '0'?
GateOverflow

Q33.

Three concurrent processes X, Y, and Z execute three different code segments that access and update certain shared variables. Process X executes the P operation (i.e., wait) on semaphores a, b and c; process Y executes the P operation on semaphores b, c and d; process Z executes the P operation on semaphores c, d, and a before entering the respective code segments. After completing the execution of its code segment, each process invokes the V operation (i.e., signal) on its three semaphores. All semaphores are binary semaphores initialized to one. Which one of the following represents a deadlock-free order of invoking the P operations by the processes?
GateOverflow

Q34.

Fetch_And_Add(X,i) is an atomic Read-Modify-Write instruction that reads the value of memory location X, increments it by the value i, and returns the old value of X. It is used in the pseudocode shown below to implement a busy-wait lock. L is an unsigned integer shared variable initialized to 0. The value of 0 corresponds to lock being available, while any non-zero value corresponds to the lock being not available. AcquireLock(L){ while (Fetch_And_Add(L,1)) L = 1; } ReleaseLock(L){ L = 0; } This implementation
GateOverflow

Q35.

Synchronization in the classical readers and writers problem can be achieved through use of semaphores. In the following incomplete code for readers-writers problem, two binary semaphores mutex and wrt are used to obtain synchronization wait (wrt) writing is performed signal (wrt) wait (mutex) readcount = readcount + 1 if readcount = 1 then S1 S2 reading is performed S3 readcount = readcount - 1 if readcount = 0 then S4 signal (mutex) The values of S1, S2, S3, S4, (in that order) are
GateOverflow

Q36.

Two processes, P1 and P2, need to access a critical section of code. Consider the following synchronization construct used by the processes: Here, wants1 and wants2 are shared variables, which are initialized to false. Which one of the following statements is TRUE about the above construct?
GateOverflow

Q37.

The wait and signal operations of a monitor are implemented using semaphores as follows. In the following, x is a condition variable, mutex is a semaphore initialized to 1, x_sem is a semaphore initialized to 0, x_count is the number of processes waiting on semaphore x_sem, initially 0, next is a semaphore initialized to 0, next_count is the number of processes waiting on semaphore next, initially 0. The body of each procedure that is visible outside the monitor is replaced with the following: P(mutex); ... body of procedure ... if (next_count > 0) V(next); else V(mutex); Each occurrence of x.wait is replaced with the following: x_count = x_count + 1; if (next_count > 0) V(next); else V(mutex); ------------------------------------------------------------ E1; x_count = x_count - 1; Each occurrence of x.signal is replaced with the following: if (x_count > 0) { next_count = next_count + 1; ------------------- E2; P(next); next_count = next_count - 1; } For correct implementation of the monitor, statements E1 and E2 are, respectively,
GateOverflow

Q38.

Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left. void barrier (void) { 1: P(S); 2: process_arrived++; 3. V(S); 4: while (process_arrived !=3); 5: P(S); 6: process_left++; 7: if (process_left==3) { 8: process_arrived = 0; 9: process_left = 0; 10: } 11: V(S); }The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally.Which one of the following rectifies the problem in the implementation?
GateOverflow

Q39.

The atomic feth-and-set x,y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x . Consider the following implementation of P and V functions on a binary semaphore S. void P(binary_semaphore*S){ unsigned y; unsigned*x =& (S->value); do { fetch-and-set x,y; } while(y); } void V (binary_semphore*S){ S_>value = 0; } Which one of the following is true?
GateOverflow

Q40.

Processes P1 and P2 use critical_flag in the following routine to achieve mutual exclusion. Assume that critical_flag is initialized to FALSE in the main program. get_exclusive_access ( ) { if (critical _flag == FALSE) { critical_flag = TRUE ; critical_region () ; critical_flag = FALSE; } } Consider the following statements. i.It is possible for both P1 and P2 to access critical_region concurrently. ii.This may lead to a deadlock. Which of the following holds?
GateOverflow